home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / ltsampledlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-31  |  36.3 KB  |  1,479 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // LTSampleDlg.cpp : implementation file
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "LTSample.h"
  16. #include "VpWnd.h"
  17. #include "LTSampleDlg.h"
  18. #include "DlgProxy.h"
  19. #include "PropDialog.h"
  20. #include "SelOptPage.h"
  21. #include "QueryDialog.h"
  22. #include "AddSymbolDlg.h"
  23. #include "SmartObjectInserDlg.h"
  24.  
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. const CLSID CLSID_Application  = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  32. const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  33.  
  34. const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  35. const IID IID_Graphics = {0x6A48110A,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  36. const IID IID_IDrawing = {0x6A481107,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
  37.  
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CAboutDlg dialog used for App About
  40.  
  41. class CAboutDlg : public CDialog
  42. {
  43. public:
  44.     CAboutDlg();
  45.  
  46. // Dialog Data
  47.     //{{AFX_DATA(CAboutDlg)
  48.     enum { IDD = IDD_ABOUTBOX };
  49.     //}}AFX_DATA
  50.  
  51.     // ClassWizard generated virtual function overrides
  52.     //{{AFX_VIRTUAL(CAboutDlg)
  53.     //}}AFX_VIRTUAL
  54.  
  55. // Implementation
  56. protected:
  57.     //{{AFX_MSG(CAboutDlg)
  58.     //}}AFX_MSG
  59.     DECLARE_MESSAGE_MAP()
  60. };
  61.  
  62. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  63. {
  64.     //{{AFX_DATA_INIT(CAboutDlg)
  65.     //}}AFX_DATA_INIT
  66. }
  67.  
  68.  
  69. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  70.     //{{AFX_MSG_MAP(CAboutDlg)
  71.         // No message handlers
  72.     //}}AFX_MSG_MAP
  73. END_MESSAGE_MAP()
  74.  
  75. /////////////////////////////////////////////////////////////////////////////
  76. // CLTSampleDlg dialog
  77.  
  78. IMPLEMENT_DYNAMIC(CLTSampleDlg, CDialog);
  79.  
  80. CLTSampleDlg::CLTSampleDlg(CWnd* pParent /*=NULL*/)
  81.     : CDialog(CLTSampleDlg::IDD, pParent)
  82. {
  83.     //{{AFX_DATA_INIT(CLTSampleDlg)
  84.         // NOTE: the ClassWizard will add member initialization here
  85.     //}}AFX_DATA_INIT
  86.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  87.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  88.     m_pAutoProxy = NULL;
  89.  
  90.     m_pLocalApp = NULL;
  91.     m_pInprocApp = NULL;
  92.     m_pApp = NULL;
  93.     m_iVersion = 0;
  94. }
  95.  
  96. CLTSampleDlg::~CLTSampleDlg()
  97. {
  98.     // If there is an automation proxy for this dialog, set
  99.     //  its back pointer to this dialog to NULL, so it knows
  100.     //  the dialog has been deleted.
  101.     if (m_pAutoProxy != NULL)
  102.         m_pAutoProxy->m_pDialog = NULL;
  103. }
  104.  
  105. BEGIN_MESSAGE_MAP(CLTSampleDlg, CDialog)
  106.     //{{AFX_MSG_MAP(CLTSampleDlg)
  107.     ON_WM_SYSCOMMAND()
  108.     ON_WM_PAINT()
  109.     ON_WM_QUERYDRAGICON()
  110.     ON_WM_CLOSE()
  111.     ON_BN_CLICKED(IDC_MERGEDRAWING, OnMergedrawing)
  112.     ON_BN_CLICKED(IDC_OPENDRAWING, OnOpendrawing)
  113.     ON_BN_CLICKED(IDC_PASTE, OnPaste)
  114.     ON_BN_CLICKED(IDC_PROPERTYSYMBOL, OnPropertysymbol)
  115.     ON_BN_CLICKED(IDC_SAVEDRAWING, OnSavedrawing)
  116.     ON_BN_CLICKED(IDC_SELECTSYMBOL, OnSelectsymbol)
  117.     ON_BN_CLICKED(IDC_CREATEAPP, OnCreateapp)
  118.     ON_BN_CLICKED(IDC_SETVIEW, OnSetview)
  119.     ON_BN_CLICKED(IDC_NEWDRAWING, OnNewdrawing)
  120.     ON_BN_CLICKED(IDC_LOCALMODE, OnLocalmode)
  121.     ON_BN_CLICKED(IDC_INPROCMODE, OnInprocmode)
  122.     ON_BN_CLICKED(IDC_DRAWINGPROPERTY, OnDrawingProperty)
  123.     ON_BN_CLICKED(IDC_CLOSEDRAWING, OnClosedrawing)
  124.     ON_BN_CLICKED(IDC_EXPLODESYMBOL, OnExplodesymbol)
  125.     ON_BN_CLICKED(IDC_QUERY, OnQuery)
  126.     ON_BN_CLICKED(IDC_COPYSYMBOL, OnCopysymbol)
  127.     ON_BN_CLICKED(IDC_ADDSYMBOL, OnAddsymbol)
  128.     ON_BN_CLICKED(IDC_REMOVESYMBOL, OnDeletesymbol)
  129.     ON_BN_CLICKED(IDC_APPPROPERTY, OnAppproperty)
  130.     ON_BN_CLICKED(IDC_OPTIONS, OnOptions)
  131.     ON_BN_CLICKED(IDC_GETBLOCK, OnGetblock)
  132.     ON_BN_CLICKED(IDC_ZOOM_IN, OnZoomIn)
  133.     ON_BN_CLICKED(IDC_ZOOM_OUT, OnZoomOut)
  134.     //}}AFX_MSG_MAP
  135. END_MESSAGE_MAP()
  136.  
  137. void CLTSampleDlg::SyncToApplication(IApplication *pApp, BOOL bGetSelection)
  138. {
  139.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  140.     if (pDwgList != NULL)        
  141.     {
  142.         int iCount = pDwgList->GetCount();
  143.         IDrawing *pIDwg = NULL;
  144.         for (int iItem = 0; iItem < iCount; iItem++)
  145.         {
  146.             pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  147.             if (pIDwg != NULL)
  148.                 pIDwg->Release();
  149.         }
  150.         pDwgList->ResetContent();
  151.     }
  152.  
  153.     if (pApp != NULL)
  154.     {
  155.         BSTR bstrVersion = NULL;
  156.         HRESULT hRes = pApp->get_Version(0, &bstrVersion);
  157.         if (SUCCEEDED(hRes)
  158.             && bstrVersion != NULL)
  159.         {
  160.             CString cstrBuild(bstrVersion);
  161.             int iDot = cstrBuild.Find('.');
  162.             CString cstrVersion = cstrBuild.Left(iDot);
  163.             m_iVersion = atoi(cstrVersion);
  164.         }
  165.         else
  166.             m_iVersion = 4;
  167.  
  168.         // Uncorrect reference counting of the Selection object
  169.         //  in SDK v 4.x - I have to correct it in the my sample
  170.         if (bGetSelection
  171.             && m_iVersion > 4)
  172.             bGetSelection = FALSE;
  173.         
  174.         // Get the handle to the drawings collection
  175.         Drawings* pDwgs = NULL;
  176.         hRes = pApp->get_Drawings(&pDwgs);
  177.         if (SUCCEEDED(hRes))
  178.         {
  179.             COleVariant varIndex;
  180.             varIndex.vt = VT_I4;
  181.  
  182.             Selection *pSelection = NULL;
  183.  
  184.             for (varIndex.lVal = 0L; ; ++varIndex.lVal)
  185.             {
  186.                 IDrawing* pIDwg = NULL;
  187.                 hRes = pDwgs->get_Item(&varIndex, &pIDwg);
  188.                 if (FAILED(hRes))
  189.                     break;
  190.                 AddDrawingToList(pDwgList, pIDwg);
  191.                 
  192.                 if (bGetSelection)
  193.                 {
  194.                     // correct reference count for the Selection object
  195.                     pIDwg->get_Selection(&pSelection);
  196.                     if (pSelection != NULL)
  197.                     {
  198.                         pSelection->AddRef();
  199.                         pSelection = NULL;
  200.                     }
  201.                 }
  202.  
  203.                 pIDwg->Release();
  204.             }
  205.             pDwgs->Release();
  206.         }
  207.     }
  208.     else
  209.         m_iVersion = 0;
  210.     CButton *pCreateAppBt = (CButton *)GetDlgItem(IDC_CREATEAPP);
  211.     if (pCreateAppBt != NULL)
  212.         pCreateAppBt->EnableWindow(pApp == NULL);
  213. }
  214.  
  215. void CLTSampleDlg::AddDrawingToList(CComboBox *pDwgList, IDrawing *pIDwg)
  216. {
  217.     if (pDwgList == NULL)
  218.         return;
  219.     if (pIDwg != NULL)
  220.     {
  221.         BSTR bstrName = NULL;
  222.         HRESULT hRes = pIDwg->get_Name(&bstrName);
  223.         if (SUCCEEDED(hRes))
  224.         {
  225.             ASSERT(bstrName != NULL);
  226.             CString strName = bstrName;
  227.             ::SysFreeString(bstrName);
  228.             int iString = pDwgList->AddString(strName);
  229.             pDwgList->SetCurSel(iString);
  230.  
  231.             pDwgList->SetItemDataPtr(iString, pIDwg);
  232.             pIDwg->AddRef();
  233.         }
  234.     }
  235. }
  236. /////////////////////////////////////////////////////////////////////////////
  237. // CLTSampleDlg message handlers
  238.  
  239. BOOL CLTSampleDlg::OnInitDialog()
  240. {
  241.     CDialog::OnInitDialog();
  242.  
  243.     m_wndView.SubclassDlgItem(IDC_TCVIEW, this);
  244.  
  245.     // Add "About..." menu item to system menu.
  246.  
  247.     // IDM_ABOUTBOX must be in the system command range.
  248.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  249.     ASSERT(IDM_ABOUTBOX < 0xF000);
  250.  
  251.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  252.     if (pSysMenu != NULL)
  253.     {
  254.         CString strAboutMenu;
  255.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  256.         if (!strAboutMenu.IsEmpty())
  257.         {
  258.             pSysMenu->AppendMenu(MF_SEPARATOR);
  259.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  260.         }
  261.     }
  262.  
  263.     // Set the icon for this dialog.  The framework does this automatically
  264.     //  when the application's main window is not a dialog
  265.     SetIcon(m_hIcon, TRUE);            // Set big icon
  266.     SetIcon(m_hIcon, FALSE);        // Set small icon
  267.     
  268.     CButton *pButton = (CButton *)GetDlgItem(IDC_LOCALMODE);
  269.     if (pButton != NULL
  270.         && ::IsWindow(pButton->GetSafeHwnd()))
  271.         pButton->SetCheck(1);
  272.  
  273.     
  274.     return TRUE;  // return TRUE  unless you set the focus to a control
  275. }
  276.  
  277. void CLTSampleDlg::OnSysCommand(UINT nID, LPARAM lParam)
  278. {
  279.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  280.     {
  281.         CAboutDlg dlgAbout;
  282.         dlgAbout.DoModal();
  283.     }
  284.     else
  285.     {
  286.         CDialog::OnSysCommand(nID, lParam);
  287.     }
  288. }
  289.  
  290. // If you add a minimize button to your dialog, you will need the code below
  291. //  to draw the icon.  For MFC applications using the document/view model,
  292. //  this is automatically done for you by the framework.
  293.  
  294. void CLTSampleDlg::OnPaint() 
  295. {
  296.     if (IsIconic())
  297.     {
  298.         CPaintDC dc(this); // device context for painting
  299.  
  300.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  301.  
  302.         // Center icon in client rectangle
  303.         int cxIcon = GetSystemMetrics(SM_CXICON);
  304.         int cyIcon = GetSystemMetrics(SM_CYICON);
  305.         CRect rect;
  306.         GetClientRect(&rect);
  307.         int x = (rect.Width() - cxIcon + 1) / 2;
  308.         int y = (rect.Height() - cyIcon + 1) / 2;
  309.  
  310.         // Draw the icon
  311.         dc.DrawIcon(x, y, m_hIcon);
  312.     }
  313.     else
  314.     {
  315.         CDialog::OnPaint();
  316.     }
  317. }
  318.  
  319. // The system calls this to obtain the cursor to display while the user drags
  320. //  the minimized window.
  321. HCURSOR CLTSampleDlg::OnQueryDragIcon()
  322. {
  323.     return (HCURSOR) m_hIcon;
  324. }
  325.  
  326. // Automation servers should not exit when a user closes the UI
  327. //  if a controller still holds on to one of its objects.  These
  328. //  message handlers make sure that if the proxy is still in use,
  329. //  then the UI is hidden but the dialog remains around if it
  330. //  is dismissed.
  331.  
  332. void CLTSampleDlg::OnClose() 
  333. {
  334.     if (CanExit())
  335.     {
  336.         CDialog::OnClose();
  337.  
  338.         m_wndView.SetView(NULL);
  339.  
  340.         CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  341.         if (pDwgList != NULL)        
  342.         {
  343.             int iCount = pDwgList->GetCount();
  344.             for (int iItem = 0; iItem < iCount; iItem++)
  345.             {
  346.                 IDrawing *pIDwg = NULL;
  347.                 pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  348.                 if (pIDwg != NULL)
  349.                     pIDwg->Release();
  350.             }
  351.         }
  352.         if (m_pLocalApp != NULL)
  353.             m_pLocalApp->Release();
  354.         if (m_pInprocApp != NULL)
  355.             m_pInprocApp->Release();
  356.     }
  357. }
  358.  
  359. void CLTSampleDlg::OnOK() 
  360. {
  361.     if (CanExit())
  362.         CDialog::OnOK();
  363. }
  364.  
  365. void CLTSampleDlg::OnCancel() 
  366. {
  367.     if (CanExit())
  368.         CDialog::OnCancel();
  369. }
  370.  
  371. BOOL CLTSampleDlg::CanExit()
  372. {
  373.     // If the proxy object is still around, then the automation
  374.     //  controller is still holding on to this application.  Leave
  375.     //  the dialog around, but hide its UI.
  376.     if (m_pAutoProxy != NULL)
  377.     {
  378.         ShowWindow(SW_HIDE);
  379.         return FALSE;
  380.     }
  381.  
  382.     return TRUE;
  383. }
  384.  
  385. static char BASED_CODE szFilter[] = "TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||";
  386.  
  387. void CLTSampleDlg::OnMergedrawing() 
  388. {
  389.     if (m_pApp == NULL)
  390.     {
  391.         AfxMessageBox(IDS_CREATEAPPFIRST);
  392.         return;
  393.     }
  394.  
  395.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  396.  
  397.     // Pointer to Drawings collection
  398.     Drawings* pDwgs = NULL;
  399.  
  400.     // Pointer to drawing intrface
  401.     IDrawing* pIDwgOpen = NULL;
  402.  
  403.     Properties *pProps = NULL;
  404.     Property *pProp = NULL;
  405.     Graphics *pGrs = NULL;
  406.  
  407.     Properties *pPropsOpen = NULL;
  408.     Property *pPropOpen = NULL;
  409.     Graphics *pGrsOpen = NULL;
  410.  
  411.     IGraphic *pIGr = NULL;
  412.     BSTR bstrPath = NULL;
  413.  
  414.     // Make a "missing" optional parameter
  415.     VARIANT varMissing;
  416.     varMissing.vt = VT_ERROR;
  417.     varMissing.scode = DISP_E_PARAMNOTFOUND;
  418.  
  419.     int iSelItem = pDwgList->GetCurSel();
  420.     if (iSelItem >= 0)
  421.     {
  422.         CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  423.         if (dlg.DoModal() != IDOK)
  424.             return;
  425.  
  426.         // Get the handle to the drawings collection
  427.         TRY
  428.         {
  429.  
  430.             IDrawing *pIDwg = NULL;
  431.             HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  432.             CHECK_HRESULT(hRes)
  433.  
  434.             // Get the file name into a BSTR
  435.             CString strPath = dlg.GetPathName();
  436.             bstrPath = strPath.AllocSysString();
  437.  
  438.             // Add the drawing to the drawings collection
  439.             hRes = pDwgs->Open(bstrPath, &varMissing, &varMissing, &pIDwgOpen);
  440.             CHECK_HRESULT(hRes)
  441.  
  442.             pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  443.             if (pIDwg != NULL)
  444.             {                
  445.                 COleVariant varPropName("TileMode");
  446.                 COleVariant varMode;
  447.                 COleVariant varOldMode;
  448.  
  449.                 hRes = pIDwgOpen->get_Properties(&pPropsOpen);
  450.                 CHECK_HRESULT(hRes)
  451.  
  452.                 hRes = pPropsOpen->get_Item(&varPropName, &pPropOpen);
  453.                 CHECK_HRESULT(hRes)
  454.  
  455.                 hRes = pIDwg->get_Properties(&pProps);
  456.                 CHECK_HRESULT(hRes)
  457.  
  458.                 hRes = pProps->get_Item(&varPropName, &pProp);
  459.                 CHECK_HRESULT(hRes)
  460.  
  461.                 hRes = pProp->get_Value(0, &varMode);
  462.                 CHECK_HRESULT(hRes)
  463.  
  464.                 varOldMode = varMode;
  465.  
  466.                 hRes = pPropOpen->put_Value(0, &varMode);
  467.                 CHECK_HRESULT(hRes)
  468.  
  469.                 hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
  470.                 CHECK_HRESULT(hRes)
  471.  
  472.                 long lCount = 0;
  473.                 hRes = pGrsOpen->get_Count(&lCount);
  474.                 CHECK_HRESULT(hRes)
  475.  
  476.                 hRes = pIDwg->get_Graphics(&pGrs);
  477.                 CHECK_HRESULT(hRes)
  478.  
  479.                 COleVariant varIndex((const long&)0);
  480.  
  481.                 long lItem = 0;
  482.                 for (lItem = 0; lItem < lCount; lItem++)
  483.                 {
  484.                     hRes = pGrsOpen->Remove(&varIndex, &pIGr);
  485.                     CHECK_HRESULT(hRes)
  486.  
  487.                     hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
  488.                     CHECK_HRESULT(hRes)
  489.                     pIGr->Release();
  490.                     pIGr = NULL;
  491.                 }
  492.  
  493.                 pGrsOpen->Release();
  494.                 pGrsOpen = NULL;
  495.  
  496.                 pGrs->Release();
  497.                 pGrs = NULL;
  498.  
  499.                 // merge next space
  500.                 if (varMode.iVal == 0)
  501.                     varMode.iVal = 1;
  502.                 else
  503.                     varMode.iVal = 0;
  504.  
  505.                 hRes = pProp->put_Value(0, &varMode);
  506.                 CHECK_HRESULT(hRes)
  507.  
  508.                 hRes = pPropOpen->put_Value(0, &varMode);
  509.                 CHECK_HRESULT(hRes)
  510.  
  511.                 hRes = pIDwgOpen->get_Graphics(&pGrsOpen);
  512.                 CHECK_HRESULT(hRes)
  513.  
  514.                 hRes = pGrsOpen->get_Count(&lCount);
  515.                 CHECK_HRESULT(hRes)
  516.  
  517.                 hRes = pIDwg->get_Graphics(&pGrs);
  518.                 CHECK_HRESULT(hRes)
  519.  
  520.                 for (lItem = 0; lItem < lCount; lItem++)
  521.                 {
  522.                     hRes = pGrsOpen->Remove(&varIndex,&pIGr);
  523.                     CHECK_HRESULT(hRes)
  524.  
  525.                     hRes = pGrs->AddGraphic(pIGr, &varMissing, &varMissing);
  526.                     CHECK_HRESULT(hRes)
  527.                     pIGr->Release();
  528.                     pIGr = NULL;
  529.                 }
  530.  
  531.             }
  532.         }
  533.         CATCH_ALL(e)
  534.         {
  535.         }
  536.         END_CATCH_ALL
  537.     }
  538.     else
  539.         OnOpendrawing();
  540.  
  541.     if (bstrPath != NULL)
  542.         ::SysFreeString(bstrPath);
  543.  
  544.     if (pIGr != NULL)
  545.         pIGr->Release();
  546.  
  547.     if (pGrsOpen != NULL)
  548.         pGrsOpen->Release();
  549.  
  550.     if (pPropOpen != NULL)
  551.         pPropOpen->Release();
  552.  
  553.     if (pPropsOpen != NULL)
  554.         pPropsOpen->Release();
  555.  
  556.     if (pGrs != NULL)
  557.         pGrs->Release();
  558.  
  559.     if (pProp != NULL)
  560.         pProp->Release();
  561.  
  562.     if (pProps != NULL)
  563.         pProps->Release();
  564.  
  565.     if (pIDwgOpen != NULL)
  566.     {
  567.         pIDwgOpen->Close(&varMissing, &varMissing, &varMissing);
  568.         pIDwgOpen->Release();
  569.     }
  570.  
  571.     if (pDwgs != NULL)
  572.         pDwgs->Release();;
  573.  
  574. }
  575.  
  576. void CLTSampleDlg::OnOpendrawing() 
  577. {
  578.     if (m_pApp == NULL)
  579.     {
  580.         AfxMessageBox(IDS_CREATEAPPFIRST);
  581.         return;
  582.     }
  583.     CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  584.     if (dlg.DoModal() != IDOK)
  585.         return;
  586.  
  587.     // Pointer to Drawings collection
  588.     Drawings* pDwgs = NULL;
  589.  
  590.     // Get the handle to the drawings collection
  591.     HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  592.     if (FAILED(hRes))
  593.     {
  594.         return;
  595.     }
  596.     
  597.     // Pointer to drawing object
  598.     IDrawing* pIDwg = NULL;
  599.  
  600.     // Make a "missing" optional parameter
  601.     VARIANT var;
  602.     var.vt = VT_ERROR;
  603.     var.scode = DISP_E_PARAMNOTFOUND;
  604.  
  605.     // Get the file name into a BSTR
  606.     CString strPath = dlg.GetPathName();
  607.     BSTR bstrPath = strPath.AllocSysString();
  608.  
  609.     // Add the drawing to the drawings collection
  610.     hRes = pDwgs->Open(bstrPath, &var, &var, &pIDwg);
  611.  
  612.     // Free the system memory for the BSTR
  613.     ::SysFreeString(bstrPath);
  614.  
  615.     if (SUCCEEDED(hRes))
  616.     {
  617.         CComboBox* pDwgsList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  618.         AddDrawingToList(pDwgsList, pIDwg);
  619.         pIDwg->Release();
  620.     }
  621.     else
  622.     {
  623.         // File was not opened.  Maybe the filter gave us a reason.
  624.         CString strDesc("Unknown");
  625.  
  626.         // Try to get thread-wide error object
  627.         IErrorInfo* pErrorInfo = NULL;
  628.         if (SUCCEEDED(::GetErrorInfo(0, &pErrorInfo)))
  629.         {
  630.             // Try to get description string
  631.             BSTR bstrDesc = NULL;
  632.             if (SUCCEEDED(pErrorInfo->GetDescription(&bstrDesc)))
  633.             {
  634.                 strDesc = bstrDesc;
  635.                 ::SysFreeString(bstrDesc);
  636.             }
  637.             pErrorInfo->Release();
  638.         }
  639.  
  640.         // Display failure message
  641.         CString msg = "Could not open '" + strPath + "': " + strDesc;
  642.         MessageBox(msg);
  643.     }
  644.  
  645.     // Finished with drawings collection, decrement reference count
  646.     pDwgs->Release();
  647.     
  648. }
  649.  
  650. void CLTSampleDlg::OnPaste() 
  651. {
  652.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  653.     if (pDwgList != NULL)
  654.     {
  655.         int iSelItem = pDwgList->GetCurSel();
  656.         if (iSelItem >= 0)
  657.         {
  658.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  659.             if (pIDwg != NULL)
  660.             {
  661.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PASTE);
  662.                 pPropBt->EnableWindow(FALSE);
  663.  
  664.                 HRESULT hRes = pIDwg->Paste();
  665.                 if (FAILED(hRes))
  666.                     AfxMessageBox(IDS_PASTEFAILED);
  667.                 pPropBt->EnableWindow(TRUE);
  668.             }
  669.             else
  670.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  671.         }
  672.     }
  673. }
  674.  
  675. void CLTSampleDlg::OnPropertysymbol() 
  676. {
  677.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  678.     if (pDwgList != NULL)
  679.     {
  680.         int iSelItem = pDwgList->GetCurSel();
  681.         if (iSelItem >= 0)
  682.         {
  683.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  684.             if (pIDwg != NULL)
  685.             {
  686.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  687.                 pPropBt->EnableWindow(FALSE);
  688.                 Selection *pSelection = NULL;
  689.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  690.                 if (SUCCEEDED(hRes))
  691.                 {
  692.                     long lCount;
  693.                     hRes = pSelection->get_Count(&lCount);
  694.                     if (SUCCEEDED(hRes))
  695.                     {
  696.                         if (lCount = 1)
  697.                         {
  698.                             IGraphic *pIGr = NULL;
  699.                             COleVariant varIndex((const long&)0);
  700.  
  701.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  702.                             if (SUCCEEDED(hRes))
  703.                             {
  704.                                 Properties *pProps = NULL;
  705.                                 hRes = pIGr->get_Properties(&pProps);
  706.                                 if (SUCCEEDED(hRes))
  707.                                 {
  708.                                     CPropDialog dlgProp(pProps, this);
  709.                                     if (dlgProp.DoModal() == IDOK)
  710.                                     {
  711.                                     }
  712.                                     pProps->Release();
  713.                                 }
  714.                                 else
  715.                                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  716.                                 pIGr->Release();
  717.                             }
  718.                             else
  719.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  720.                         }
  721.                         else
  722.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  723.                     }
  724.                     else
  725.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  726.                     pSelection->Release();
  727.                 }
  728.                 else
  729.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  730.                 pPropBt->EnableWindow(TRUE);
  731.             }
  732.             else
  733.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  734.         }
  735.     }
  736. }
  737.  
  738. void CLTSampleDlg::OnSavedrawing() 
  739. {
  740.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  741.     HRESULT hRes = S_OK;
  742.     if (pDwgList != NULL)        
  743.     {
  744.         CButton *pSaveBt = (CButton *)GetDlgItem(IDC_SAVEDRAWING);
  745.         pSaveBt->EnableWindow(FALSE);
  746.  
  747.         int iItem = pDwgList->GetCurSel();
  748.         if (iItem >= 0)
  749.         {
  750.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  751.             if (pIDwg != NULL)
  752.             {
  753.                 CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  754.                 if (dlg.DoModal() == IDOK)
  755.                 {
  756.                     // Make a "missing" optional parameter
  757.                     VARIANT var;
  758.                     var.vt = VT_ERROR;
  759.                     var.scode = DISP_E_PARAMNOTFOUND;
  760.  
  761.                     // Get the file name into a BSTR
  762.                     CString strPath = dlg.GetPathName();
  763.                     BSTR bstrPath = strPath.AllocSysString();
  764.  
  765.                     HRESULT hRes = pIDwg->SaveAs(bstrPath, &var);
  766.  
  767.                     // Free the system memory for the BSTR
  768.                     ::SysFreeString(bstrPath);
  769.                 }
  770.             }
  771.         }
  772.         else
  773.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  774.         pSaveBt->EnableWindow(TRUE);
  775.     }
  776. }
  777.  
  778. void CLTSampleDlg::OnSelectsymbol() 
  779. {
  780.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  781.     HRESULT hRes = S_OK;
  782.     if (pDwgList != NULL)        
  783.     {
  784.         CButton *pSelectBt = (CButton *)GetDlgItem(IDC_SELECTSYMBOL);
  785.         if (pSelectBt->IsWindowEnabled())
  786.         {
  787.             int iItem = pDwgList->GetCurSel();
  788.             if (iItem >= 0)
  789.             {
  790.                 IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  791.                 if (pIDwg != NULL)
  792.                 {
  793.                     Selection *pSel = NULL;
  794.                     hRes = pIDwg->get_Selection(&pSel);
  795.                     if (SUCCEEDED(hRes))
  796.                     {
  797.                         pSel->Unselect();
  798.                         pSel->Release();
  799.                     }
  800.                 }
  801.                 m_wndView.SetSelectMode();
  802.                 pSelectBt->EnableWindow(FALSE);
  803.             }
  804.             else
  805.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  806.         }
  807.         else
  808.         {
  809.             pSelectBt->EnableWindow(TRUE);
  810.             m_wndView.SetSelectMode();
  811.         }
  812.     }
  813. }
  814.  
  815. void CLTSampleDlg::OnCreateapp() 
  816. {
  817.     CButton *pBtCreate = (CButton *)GetDlgItem(IDC_CREATEAPP);
  818.     if (pBtCreate != NULL
  819.         && ::IsWindow(pBtCreate->GetSafeHwnd()))
  820.         pBtCreate->EnableWindow(FALSE);
  821.  
  822.     int iLocal = 0;
  823.     CButton *pBtLocal = (CButton *)GetDlgItem(IDC_LOCALMODE);
  824.     if (pBtLocal != NULL
  825.         && ::IsWindow(pBtLocal->GetSafeHwnd()))
  826.         iLocal = pBtLocal->GetCheck();
  827.  
  828.     int iInproc = 0;
  829.     CButton *pBtInproc = (CButton *)GetDlgItem(IDC_INPROCMODE);
  830.     if (pBtInproc != NULL
  831.         && ::IsWindow(pBtInproc->GetSafeHwnd()))
  832.         iInproc = pBtInproc->GetCheck();
  833.  
  834.     HRESULT hRes = S_OK;
  835.     if (iLocal == 1)
  836.     {
  837.         ASSERT(iInproc != 1);
  838.         if (m_pLocalApp == NULL)
  839.         {
  840.             IUnknown* pIUnk = NULL;
  841.             hRes = ::GetActiveObject(CLSID_Application, NULL, &pIUnk);
  842.             if (FAILED(hRes))
  843.             {
  844.                 hRes = CoCreateInstance(CLSID_Application,    //Class identifier (CLSID) of the object
  845.                                         NULL,    //Object is or isn't part of an aggregate 
  846.                                         CLSCTX_LOCAL_SERVER,    //Context for running executable code
  847.                                         IID_IUnknown,    //Interface identifier
  848.                                         (void**)&pIUnk    //Points to requested interface pointer
  849.                 );    
  850.  
  851.                 if (FAILED(hRes))
  852.                 {
  853.                     AfxMessageBox(IDS_COULDNOTCREATELOCALSERVER);
  854.                     return;
  855.                 }
  856.             }
  857.  
  858.             hRes = pIUnk->QueryInterface(IID_IApplication, (void**)&m_pLocalApp);
  859.             pIUnk->Release();
  860.             if (FAILED(hRes))
  861.             {
  862.                 AfxMessageBox(IDS_OBJECTISNOTTURBOCADAPPLICATION);
  863.             }
  864.         }
  865.         else
  866.             AfxMessageBox(IDS_LOCALSERVERALREADYRUNNING);
  867.         m_pApp = m_pLocalApp;
  868.     }
  869.     else if (iInproc == 1)
  870.     {
  871.         if (m_pInprocApp == NULL)
  872.         {
  873.             hRes = CoCreateInstance(CLSID_XApplication,    //Class identifier (CLSID) of the object
  874.                                     NULL,    //Object is or isn't part of an aggregate
  875.                                     CLSCTX_INPROC_SERVER,    //Context for running executable code
  876.                                     IID_IApplication,    //Interface identifier
  877.                                     (void**)&m_pInprocApp    //Points to requested interface pointer
  878.             );
  879.  
  880.             if (FAILED(hRes))
  881.                 AfxMessageBox(IDS_COULDNOTCREATEINPROCSERVER);
  882.     
  883.         }
  884.         else
  885.             AfxMessageBox(IDS_INPROCSERVERALREADYCREATED);
  886.         m_pApp = m_pInprocApp;
  887.     }
  888.     else
  889.         ASSERT(FALSE);
  890.  
  891.     // uncorrect reference counting of the Selection object
  892.     // in SDK v 4.x - I have to correct it in the my sample
  893.     // when create Application object
  894.     SyncToApplication(m_pApp, TRUE);
  895.     if (m_pApp != NULL)
  896.         AfxMessageBox(IDS_APPCOMPLETE);
  897. }
  898.  
  899.  
  900. void CLTSampleDlg::OnSetview() 
  901. {
  902.     
  903.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  904.     if (pDwgList != NULL)        
  905.     {
  906.         int iItem = pDwgList->GetCurSel();
  907.         if (iItem >= 0)
  908.         {
  909.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iItem);
  910.             Views *pViews = NULL;
  911.             HRESULT hRes = pIDwg->get_Views(&pViews);
  912.             if (SUCCEEDED(hRes))
  913.             {
  914.                 // Pointer to view object
  915.                 View* pView = NULL;
  916.  
  917.                 // Make a "missing" optional parameter
  918.                 VARIANT var;
  919.                 var.vt = VT_ERROR;
  920.                 var.scode = DISP_E_PARAMNOTFOUND;
  921.  
  922.                 // Add the view to the collection
  923.                 hRes = pViews->Add(&var, &var, &pView);
  924.  
  925.                 if (SUCCEEDED(hRes))
  926.                 {
  927.                     // Set up view to be the active view
  928.                     m_wndView.SetView(pView);
  929.  
  930.                     // Finished with view, decrement reference count
  931.                     pView->Release();
  932.                 }
  933.  
  934.                 // Finished with views, decrement reference count
  935.                 pViews->Release();
  936.             }
  937.         }
  938.         else
  939.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  940.     }
  941. }
  942.  
  943. void CLTSampleDlg::OnNewdrawing() 
  944. {
  945.     if (m_pApp == NULL)
  946.     {
  947.         AfxMessageBox(IDS_CREATEAPPFIRST);
  948.         return;
  949.     }
  950.  
  951.     Drawings* pDwgs = NULL;
  952.  
  953.     // Get the handle to the drawings collection
  954.     HRESULT hRes = m_pApp->get_Drawings(&pDwgs);
  955.     if (FAILED(hRes))
  956.     {
  957.         return;
  958.     }
  959.     
  960.     // Pointer to drawing object
  961.     IDrawing* pIDwg = NULL;
  962.  
  963.     // Make a "missing" optional parameter
  964.     VARIANT var;
  965.     var.vt = VT_ERROR;
  966.     var.scode = DISP_E_PARAMNOTFOUND;
  967.  
  968.     // Add the drawing to the drawings collection
  969.     hRes = pDwgs->Add(&var, &pIDwg);
  970.     if (SUCCEEDED(hRes))
  971.     {
  972.         CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  973.         AddDrawingToList(pDwgList, pIDwg);
  974.         pIDwg->Release();
  975.     }
  976.  
  977.     // Finished with drawings collection, decrement reference count
  978.     pDwgs->Release();
  979. }
  980.  
  981. void CLTSampleDlg::OnLocalmode() 
  982. {
  983.     m_pApp = m_pLocalApp;
  984.     SyncToApplication(m_pApp);
  985. }
  986.  
  987. void CLTSampleDlg::OnInprocmode() 
  988. {
  989.     m_pApp = m_pInprocApp;
  990.     SyncToApplication(m_pApp);
  991. }
  992.  
  993. void CLTSampleDlg::OnDrawingProperty() 
  994. {
  995.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  996.     if (pDwgList != NULL)
  997.     {
  998.         int iSelItem = pDwgList->GetCurSel();
  999.         if (iSelItem >= 0)
  1000.         {
  1001.             CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
  1002.             pPropBt->EnableWindow(FALSE);
  1003.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1004.             if (pIDwg != NULL)
  1005.             {
  1006.                 Properties *pProps = NULL;
  1007.                 HRESULT hRes = pIDwg->get_Properties(&pProps);
  1008.                 if (SUCCEEDED(hRes))
  1009.                 {
  1010.                     CPropDialog dlgProp(pProps, this);
  1011.                     if (dlgProp.DoModal() == IDOK)
  1012.                     {
  1013.                     }
  1014.                     pProps->Release();
  1015.                 }
  1016.                 else
  1017.                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1018.             }
  1019.             pPropBt->EnableWindow(TRUE);
  1020.         }
  1021.         else
  1022.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1023.     }
  1024. }
  1025.  
  1026. void CLTSampleDlg::OnClosedrawing() 
  1027. {
  1028.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1029.     if (pDwgList != NULL)
  1030.     {
  1031.         int iSelItem = pDwgList->GetCurSel();
  1032.         if (iSelItem >= 0)
  1033.         {
  1034.             CButton *pPropBt = (CButton *)GetDlgItem(IDC_DRAWINGPROPERTY);
  1035.             pPropBt->EnableWindow(FALSE);
  1036.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1037.             if (pIDwg != NULL)
  1038.             {
  1039.                 IDrawing *pIDwgView = m_wndView.GetDrawing();
  1040.                 if (pIDwgView == pIDwg)
  1041.                 {
  1042.                     m_wndView.SetView(NULL);
  1043.                     m_wndView.Invalidate();
  1044.                     m_wndView.UpdateWindow();
  1045.                     pIDwgView->Release();
  1046.                 }
  1047.  
  1048.                 VARIANT var;
  1049.                 var.vt = VT_ERROR;
  1050.                 var.scode = DISP_E_PARAMNOTFOUND;
  1051.                 pIDwg->Close(&var, &var, &var);
  1052.                 pIDwg->Release();
  1053.  
  1054.                 pDwgList->DeleteString(iSelItem);
  1055.                 pDwgList->SetCurSel(iSelItem - 1);
  1056.             }
  1057.             pPropBt->EnableWindow(TRUE);
  1058.         }
  1059.         else
  1060.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1061.     }    
  1062. }
  1063.  
  1064. void CLTSampleDlg::OnExplodesymbol() 
  1065. {
  1066.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1067.     if (pDwgList != NULL)
  1068.     {
  1069.         int iSelItem = pDwgList->GetCurSel();
  1070.         if (iSelItem >= 0)
  1071.         {
  1072.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1073.             if (pIDwg != NULL)
  1074.             {
  1075.                 CButton *pExplBt = (CButton *)GetDlgItem(IDC_EXPLODESYMBOL);
  1076.                 pExplBt->EnableWindow(FALSE);
  1077.                 Selection *pSelection = NULL;
  1078.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1079.                 if (SUCCEEDED(hRes))
  1080.                 {
  1081.                     long lCount;
  1082.                     hRes = pSelection->get_Count(&lCount);
  1083.                     if (SUCCEEDED(hRes))
  1084.                     {
  1085.                         if (lCount = 1)
  1086.                         {
  1087.                             IGraphic *pIGr = NULL;
  1088.                             COleVariant varIndex((const long&)0);
  1089.  
  1090.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  1091.                             if (SUCCEEDED(hRes))
  1092.                             {
  1093.                                 GraphicSet *pSet = NULL;
  1094.                                 hRes = pIGr->Explode(&pSet);
  1095.                                 if (SUCCEEDED(hRes))
  1096.                                 {
  1097.                                     pSet->Release();
  1098.                                 }
  1099.                                 else
  1100.                                     AfxMessageBox(IDS_CANNOTEXPLODEGRAPHIC);
  1101.                                 pIGr->Release();
  1102.                             }
  1103.                             else
  1104.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1105.                         }
  1106.                         else
  1107.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1108.                     }
  1109.                     else
  1110.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1111.                     pSelection->Release();
  1112.                 }
  1113.                 else
  1114.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1115.                 pExplBt->EnableWindow(TRUE);
  1116.             }
  1117.             else
  1118.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1119.         }
  1120.     }
  1121. }
  1122.  
  1123. void CLTSampleDlg::OnQuery() 
  1124. {
  1125.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1126.     if (pDwgList != NULL)
  1127.     {
  1128.         int iSelItem = pDwgList->GetCurSel();
  1129.         if (iSelItem >= 0)
  1130.         {
  1131.             CButton *pQueryBt = (CButton *)GetDlgItem(IDC_QUERY);
  1132.             pQueryBt->EnableWindow(FALSE);
  1133.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1134.             if (pIDwg != NULL)
  1135.             {
  1136.                 Graphics *pGrs = NULL;
  1137.                 HRESULT hRes = pIDwg->get_Graphics(&pGrs);
  1138.                 if (SUCCEEDED(hRes))
  1139.                 {
  1140.                     CQueryDialog dlgQuery(this);
  1141.                     if (dlgQuery.DoModal() == IDOK)
  1142.                     {
  1143.                         GraphicSet *pGrSet = NULL;
  1144.                         BSTR bstrQuery = dlgQuery.m_cstrQueryString.AllocSysString();
  1145.                         hRes = pGrs->QuerySet(bstrQuery, &pGrSet);
  1146.                         if (SUCCEEDED(hRes))
  1147.                         {
  1148.                             if (pGrSet != NULL)
  1149.                             {
  1150.                                 hRes = pGrSet->Select();
  1151.                                 if (SUCCEEDED(hRes))
  1152.                                     AfxMessageBox(IDS_QUERYSET_SUCCEEDED);
  1153.                                 else
  1154.                                     AfxMessageBox(IDS_CANNOTSELECTGRAPHIC);
  1155.                                 pGrSet->Release();
  1156.                             }
  1157.                             m_wndView.Invalidate();
  1158.                             m_wndView.UpdateWindow();
  1159.                         }
  1160.                         else
  1161.                             AfxMessageBox(IDS_QUERYSET_FAILED);
  1162.                         ::SysFreeString(bstrQuery);
  1163.                     }
  1164.                     pGrs->Release();
  1165.                 }
  1166.                 else
  1167.                     AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1168.             }
  1169.             pQueryBt->EnableWindow(TRUE);
  1170.         }
  1171.         else
  1172.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1173.     }
  1174. }
  1175.  
  1176. void CLTSampleDlg::OnCopysymbol() 
  1177. {
  1178.     // TODO: Add your control notification handler code here
  1179.     
  1180. }
  1181.  
  1182. void CLTSampleDlg::OnAddsymbol() 
  1183. {
  1184.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1185.     if (pDwgList != NULL)
  1186.     {
  1187.         int iSelItem = pDwgList->GetCurSel();
  1188.         if (iSelItem >= 0)
  1189.         {
  1190.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1191.             if (pIDwg != NULL)
  1192.             {
  1193.                 CAddSymbolDlg dlgAdd(this);
  1194.                 if (dlgAdd.DoModal() == IDOK)
  1195.                 {
  1196.                     HRESULT hRes = S_OK;
  1197.                     switch (dlgAdd.m_iInsert)
  1198.                     {
  1199.                         case 0:
  1200.                         {
  1201.                             RegenMethods *pRegens = NULL;
  1202.                             hRes = m_pApp->get_RegenMethods(&pRegens);
  1203.                             if (SUCCEEDED(hRes))
  1204.                             {
  1205.                                 CSmartObjectInserDlg dlgInsert(pRegens, this);
  1206.                                 if (dlgInsert.DoModal())
  1207.                                 {
  1208.                                     VARIANT varMissing;
  1209.                                     ::VariantInit(&varMissing);
  1210.                                     varMissing.vt = VT_ERROR;
  1211.                                     varMissing.scode = DISP_E_PARAMNOTFOUND;
  1212.                                     
  1213.                                     VARIANT varType;
  1214.                                     ::VariantInit(&varType);
  1215.                                     varType.vt = VT_I4;
  1216.                                     varType.lVal = imsiPolyline;
  1217.  
  1218.                                     VARIANT varRegenType;
  1219.                                     ::VariantInit(&varRegenType);
  1220.                                     varRegenType.vt = VT_I4;
  1221.                                     varRegenType.lVal = dlgInsert.m_dwID;
  1222.  
  1223.                                     IGraphic *pIGr = NULL;
  1224.                                     Graphics *pGrs = NULL;
  1225.                                     hRes = pIDwg->get_Graphics(&pGrs);
  1226.                                     if (SUCCEEDED(hRes))
  1227.                                     {
  1228.                                         
  1229.                                         switch (dlgInsert.m_rmType)
  1230.                                         {
  1231.                                             case imsiAutomation:
  1232.                                             {
  1233.                                                 hRes = pGrs->Add(&varType,
  1234.                                                                  &varRegenType,
  1235.                                                                  &varMissing,
  1236.                                                                  &varMissing,
  1237.                                                                  &varMissing,
  1238.                                                                  &varMissing,
  1239.                                                                  &pIGr);
  1240.                                             }
  1241.                                             break;
  1242.                                             case imsiVTbl:
  1243.                                                 AfxMessageBox(IDS_NOTIMPLEMENTED);
  1244.                                             break;
  1245.                                             case imsiScript:
  1246.                                                 AfxMessageBox(IDS_NOTIMPLEMENTED);
  1247.                                             break;
  1248.                                         }
  1249.                                         if (pIGr != NULL)
  1250.                                             pIGr->Release();
  1251.                                         pGrs->Release();
  1252.                                     }
  1253.                                     else
  1254.                                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1255.                                 }
  1256.                             }
  1257.                             else
  1258.                                 AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1259.                         }
  1260.                         break;
  1261.                         case 1:
  1262.                         default:
  1263.                             AfxMessageBox(IDS_NOTIMPLEMENTED);
  1264.                         break;
  1265.                     }
  1266.                 }
  1267.             }
  1268.             else
  1269.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1270.         }
  1271.         else
  1272.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1273.     }
  1274. }
  1275.  
  1276. void CLTSampleDlg::OnDeletesymbol() 
  1277. {
  1278.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1279.     if (pDwgList != NULL)
  1280.     {
  1281.         int iSelItem = pDwgList->GetCurSel();
  1282.         if (iSelItem >= 0)
  1283.         {
  1284.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1285.             if (pIDwg != NULL)
  1286.             {
  1287.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  1288.                 pPropBt->EnableWindow(FALSE);
  1289.                 Selection *pSelection = NULL;
  1290.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1291.                 if (SUCCEEDED(hRes))
  1292.                 {
  1293.                     long lCount;
  1294.                     hRes = pSelection->get_Count(&lCount);
  1295.                     if (SUCCEEDED(hRes))
  1296.                     {
  1297.                         IGraphic *pIGr = NULL;
  1298.                         COleVariant varIndex((const long&)0);
  1299.  
  1300.                         hRes = pSelection->get_Item(varIndex, &pIGr);
  1301.                         if (SUCCEEDED(hRes))
  1302.                         {
  1303.                             long index;
  1304.                             hRes = pIGr->get_Index(&index);
  1305.                             if (SUCCEEDED(hRes))
  1306.                             {
  1307.                                 IDispatch *pIDisp = NULL;
  1308.                                 hRes = pIGr->get_Parent(&pIDisp);
  1309.                                 if (SUCCEEDED(hRes))
  1310.                                 {
  1311.                                     Graphics *pGrs = NULL;
  1312.                                     IDrawing *pIDwg = NULL;
  1313.                                     hRes = pIDisp->QueryInterface(IID_IDrawing, (void **)&pIDwg);
  1314.                                     if (SUCCEEDED(hRes))
  1315.                                         hRes = pIDwg->get_Graphics(&pGrs);
  1316.                                     else
  1317.                                         hRes = pIDisp->QueryInterface(IID_Graphics, (void **)&pGrs);
  1318.                                     pIDisp->Release();
  1319.                                     if (SUCCEEDED(hRes))
  1320.                                     {
  1321.                                         varIndex = index;
  1322.                                         IGraphic *pIGrRemoved = NULL;
  1323.                                         hRes = pGrs->Remove(&varIndex, &pIGrRemoved);
  1324.                                         if (SUCCEEDED(hRes))
  1325.                                         {
  1326.                                             AfxMessageBox(IDS_SYMBOLREMOVEDFROMDRAWING);
  1327.                                             pIGrRemoved->Release();
  1328.                                         }
  1329.                                         pGrs->Release();
  1330.                                     }
  1331.                                 }
  1332.                             }
  1333.                             pIGr->Release();
  1334.                         }
  1335.                         else
  1336.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1337.                     }
  1338.                     else
  1339.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1340.                     pSelection->Release();
  1341.                 }
  1342.                 else
  1343.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1344.                 pPropBt->EnableWindow(TRUE);
  1345.             }
  1346.         }
  1347.         else
  1348.             AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1349.     }
  1350. }
  1351.  
  1352. void CLTSampleDlg::OnAppproperty() 
  1353. {
  1354.     if (m_pApp != NULL)
  1355.     {
  1356.         CButton *pAppPropsBt = (CButton *)GetDlgItem(IDC_APPPROPERTY);
  1357.         if (pAppPropsBt != NULL)
  1358.             pAppPropsBt->EnableWindow(FALSE);
  1359.         Properties *pProps = NULL;
  1360.         HRESULT hRes = m_pApp->get_Properties(&pProps);
  1361.         if (SUCCEEDED(hRes))
  1362.         {
  1363.             CPropDialog dlgProp(pProps, this);
  1364.             if (dlgProp.DoModal() == IDOK)
  1365.             {
  1366.             }
  1367.             pProps->Release();
  1368.         }
  1369.         else
  1370.             AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1371.         if (pAppPropsBt != NULL)
  1372.             pAppPropsBt->EnableWindow(TRUE);
  1373.     }
  1374.     else
  1375.         AfxMessageBox(IDS_CREATEAPPFIRST);
  1376.     
  1377. }
  1378.  
  1379. void CLTSampleDlg::OnOptions() 
  1380. {
  1381.     CPropertySheet     sheet("Options", this);
  1382.     CSelOptPage    select;
  1383.  
  1384.     select.m_iVersion    = m_iVersion;
  1385.     select.m_bTopLevel    = m_wndView.m_varTopLevel.boolVal;
  1386.     select.m_bInvisible    = m_wndView.m_varInvisible.boolVal;
  1387.     select.m_bSegments    = m_wndView.m_varSegments.boolVal;
  1388.     select.m_bArcs        = m_wndView.m_varArcs.boolVal;
  1389.     select.m_bTexts        = m_wndView.m_varTexts.boolVal;
  1390.     select.m_bBlocks    = m_wndView.m_varBlocks.boolVal;
  1391.  
  1392.     sheet.AddPage(&select);
  1393.     if (sheet.DoModal() == IDOK)
  1394.     {
  1395.         m_wndView.m_varTopLevel.boolVal        = select.m_bTopLevel;
  1396.         m_wndView.m_varInvisible.boolVal    = select.m_bInvisible;
  1397.         m_wndView.m_varSegments.boolVal        = select.m_bSegments;
  1398.         m_wndView.m_varArcs.boolVal            = select.m_bArcs;
  1399.         m_wndView.m_varTexts.boolVal        = select.m_bTexts;
  1400.         m_wndView.m_varBlocks.boolVal        = select.m_bBlocks;
  1401.     }
  1402. }
  1403.  
  1404. void CLTSampleDlg::OnGetblock() 
  1405. {
  1406.     CComboBox *pDwgList = (CComboBox*)GetDlgItem(IDC_DRAWINGLIST);
  1407.     if (pDwgList != NULL)
  1408.     {
  1409.         int iSelItem = pDwgList->GetCurSel();
  1410.         if (iSelItem >= 0)
  1411.         {
  1412.             IDrawing *pIDwg = (IDrawing *)pDwgList->GetItemDataPtr(iSelItem);
  1413.             if (pIDwg != NULL)
  1414.             {
  1415.                 CButton *pPropBt = (CButton *)GetDlgItem(IDC_PROPERTYSYMBOL);
  1416.                 pPropBt->EnableWindow(FALSE);
  1417.                 Selection *pSelection = NULL;
  1418.                 HRESULT hRes = pIDwg->get_Selection(&pSelection);
  1419.                 if (SUCCEEDED(hRes))
  1420.                 {
  1421.                     long lCount;
  1422.                     hRes = pSelection->get_Count(&lCount);
  1423.                     if (SUCCEEDED(hRes))
  1424.                     {
  1425.                         if (lCount = 1)
  1426.                         {
  1427.                             IGraphic *pIGr = NULL;
  1428.                             COleVariant varIndex((const long&)0);
  1429.  
  1430.                             hRes = pSelection->get_Item(varIndex, &pIGr);
  1431.                             if (SUCCEEDED(hRes))
  1432.                             {
  1433.                                 Block *pBlock = NULL;
  1434.                                 hRes = pIGr->get_Block(&pBlock);
  1435.                                 if (SUCCEEDED(hRes) && pBlock)
  1436.                                 {
  1437.                                     pBlock->Release();
  1438.                                 }
  1439.                                 else
  1440.                                     AfxMessageBox(IDS_CANNOTGETBLOCK);
  1441.                                 pIGr->Release();
  1442.                             }
  1443.                             else
  1444.                                 AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1445.                         }
  1446.                         else
  1447.                             AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1448.                     }
  1449.                     else
  1450.                         AfxMessageBox(IDS_CANNOTGETCOLLECTION);
  1451.                     pSelection->Release();
  1452.                 }
  1453.                 else
  1454.                     AfxMessageBox(IDS_SELECTONESYMBOLONLY);
  1455.                 pPropBt->EnableWindow(TRUE);
  1456.             }
  1457.             else
  1458.                 AfxMessageBox(IDS_SELECTDRAWINGFIRST);
  1459.         }
  1460.     }
  1461. }
  1462.  
  1463. void CLTSampleDlg::OnZoomIn() 
  1464. {
  1465.     CString strStr;
  1466.     strStr.LoadString(IDS_ADDYOUR_CODE_HERE);
  1467.     AfxMessageBox(strStr);
  1468.     // TODO: Add your control notification handler code here
  1469. }
  1470.  
  1471. void CLTSampleDlg::OnZoomOut() 
  1472. {
  1473.     CString strStr;
  1474.     strStr.LoadString(IDS_ADDYOUR_CODE_HERE);
  1475.     AfxMessageBox(strStr);
  1476.     // TODO: Add your control notification handler code here
  1477.     
  1478. }
  1479.